package com.cet.qz.unit01.chapter1_3;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-04-01 20:41
 **/
public class Qz1_3_1 {
    public static void main(String[] args) {
        FixedCapcityStackOfStrings stack = new FixedCapcityStackOfStrings(5);
        stack.push("a");
        stack.push("a");
        stack.push("a");
        stack.push("a");
        stack.push("a");
        System.out.println(stack.pop());
        stack.push("b");
    }
}

class FixedCapcityStackOfStrings {
    private String[] stack;

    private int N; //栈顶指针

    public FixedCapcityStackOfStrings(int capcity) {
        stack = new String[capcity];
    }

    public boolean isEmpty() {
        return N == 0;
    }

    public int size() {
        return N;
    }

    public boolean isFull() {
        return N == stack.length;
    }

    public void push(String str) {
        if (isFull()) {
            throw new RuntimeException("FixedCapcityStackOfStrings is full!");
        }

        stack[N++] = str;
    }

    public String pop() {
        if (isEmpty()) {
            throw new RuntimeException("FixedCapcityStackOfStrings is empty!");
        }
        return stack[--N];
    }
}
